const express = require("express")
const data = require("./data/index.json")
const app = express()
app.get("/",(request,response)=>{
    let str = `<ul></ul>`
    data.forEach(item=>{
        str += `<li><a href="/detail/${item.id}">${item.newsTitle}</a></li>`
    })
    str+=`</ul>`
    response.send(str)
})
app.get("/detail/:id",(request,response)=>{
    let {id} = request.params
    // let {newsTitle,newsContent} = data.find(function(item){
    //     return item.id=id
    // })
    let {newsTitle,newsContent} = data.find((item)=>item.id===id)
    let str = `
        <h3>${newsTitle}</h3>
        <p>${newsContent}</p>
    `
    response.send(str)
})
app.listen(80,()=>{
    console.log("success");
})